﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Derbster.Domain
{
    public class Scoring : IEnumerable<ScoringPass>
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int ScoringId { get; set; }
        public bool Lost { get; internal set; }
        public bool Lead { get; internal set; }
        public bool NoPass { get; internal set; }
        public bool Called { get; internal set; }
        public bool Injury { get; internal set; }
        public bool StarPassed { get; internal set; }
        public HashSet<ScoringPass> Passes { get; internal set; }
       
        [ContractVerification(false)]
        internal Scoring()
        {
           
        }

        public Scoring(Jam jam)
        {
            Contract.Requires(jam != null);
            Passes = new HashSet<ScoringPass>();
        }

        public bool IsLead
        {
            get
            {
                return Lead && !Lost;
            }
        }

        public bool VerifyScoring()
        {
            Contract.Requires(Passes != null);
            if (!Passes.All(pass => pass.VerifyPass())) return false;

            return true;
        }

        public IEnumerator<ScoringPass> GetEnumerator()
        {
            Contract.Assume(Passes != null);
            return Passes.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
